import dt from '@dt/dt'
import activityMgr from '@/biz/customerForCode/activity'
import pointMgr from '@/biz/customerForCode/point'
import ruleOpt from '@/biz/option/rule.js'

let _this = null

function channel() {
  console.log(_this.isEdit)
  if (!_this.isEdit) {
    let editChannel = {
      title: '渠道',
      key: 'channelId',
      col: 16,
      select: {
        options: [],
        clearable: false
      },
      rules: [ruleOpt.required('请选择渠道')]
    }
    activityMgr
      .getAppropriateByBuildingId({
        buildingId: dt.buildInfo().housesId,
        validate: 1,
        type: 1
      })
      .then((res) => {
        editChannel.select.options = res
      })
    return editChannel
  } else {
    let checkChannel = {
      title: '渠道',
      key: 'channelName',
      col: 20,
      text: {
        margin: '0 0 24px 0'
      }
    }
    return checkChannel
  }
}

function options(vm) {
  _this = vm
  return [
    {
      title: '活动名称',
      key: 'activityName',
      col: 24,
      group: [
        {
          placeholder: '请输入活动名称',
          key: 'activityName',
          col: 16,
          input: { maxlength: 10 }
        }
      ],

      rules: [
        {
          required: true,
          message: '活动名称不能为空',
          trigger: 'blur'
        }
      ]
    },
    {
      placeholder: '活动名一般用于区分不同的拓客场景,例如：小区拓客，超市拓客，企业拓客，渠道合作拓客等',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    {
      placeholder: '客户扫了该活动的拓客码后，会进入线上售楼处并授权成为线索',
      text: {
        show: true,
        color: '#FFA000',
        tooltip: false,
        margin: '0 0 24px 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    channel(),
    {
      placeholder: '渠道指生成的线索客户会统计入该渠道，同时客户到访时也便于了解客户的来源',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    {
      placeholder:
        '例如：渠道合作时选—“小胖看房”，小区地拓时选—“地拓（社区）”，超市地拓时选—“地拓（商场）”等',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    {
      placeholder: '如果没有合适渠道，您也可以在案场配置手动新建合适的渠道',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    }
  ]
}
function pointPositionOpt(vm) {
  _this = vm
  return [
    {
      title: '拓客码',
      key: 'tokerId',
      placeholder: '请选择拓客码',
      col: 18,
      disabled: _this.isEdit,
      visible: _this.isActivity,
      load: (o) => {
        pointMgr.getTokerAndChannelList({ id: _this.$route.query.activityId }).then((res) => {
          res &&
            res.forEach((item) => {
              item.key = item.tokerId
              item.value = item.tokerName
            })
          o.select.options = res
        })
      },
      select: {
        options: []
      },
      change: (data) => {
        console.log(data)
        let channel = data.option.select.options.filter((item) => {
          if (item.tokerId == data.value) {
            return item
          }
        })
        console.log(channel)
        _this.info.channelName = channel[0].channelName
        // _this.updateOpt()
      },
      rules: [
        {
          required: true,
          message: '拓客码不能为空',
          trigger: 'blur'
        }
      ]
    },
    {
      title: '渠道',
      key: 'channelName',
      col: 20,
      visible: _this.isActivity,
      text: {
        margin: '0 0 24px 0'
      }
    },
    {
      title: '点位',
      key: 'pointPositionName',
      placeholder: '请输入点位名',
      col: 18,
      input: { maxlength: 10 },
      rules: [
        {
          required: true,
          message: '点位不能为空',
          trigger: 'blur'
        }
      ]
    }
  ]
}
function ExpandCodeOpt(vm) {
  _this = vm
  return [
    {
      title: '拓客码名',
      key: 'tokerName',
      col: 24,
      group: [
        {
          placeholder: '请输入拓客码名',
          key: 'tokerName',
          col: 16,
          input: { maxlength: 10 }
        }
      ],

      rules: [
        {
          required: true,
          message: '活动名称不能为空',
          trigger: 'blur'
        }
      ]
    },
    {
      placeholder:
        '拓客码名一般用于区分不同的拓客场景,例如：小区拓客码，超市拓客码，企业拓客码，渠道合作拓客码等',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    {
      placeholder: '客户扫了该拓客码后，会进入抽奖活动页面并授权成为线索',
      text: {
        show: true,
        color: '#FFA000',
        tooltip: false,
        margin: '0 0 24px 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    channel(),
    {
      placeholder: '渠道指生成的线索客户会统计入该渠道，同时客户到访时也便于了解客户的来源',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    {
      placeholder:
        '例如：渠道合作时选—“小胖看房”，小区地拓时选—“地拓（社区）”，超市地拓时选—“地拓（商场）”等',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    },
    {
      placeholder: '如果没有合适渠道，您也可以在案场配置手动新建合适的渠道',
      text: {
        show: true,
        color: '#999999',
        tooltip: false,
        margin: '0 0 0 80px',
        fontSize: '12px',
        lineHeight: '20px'
      }
    }
  ]
}
export default {
  options,
  pointPositionOpt,
  ExpandCodeOpt
}
